

#include "BSP.h"
#include "BSP_Config.h"
#include "IO.h"


static const IO_T GT20L16_CS = IO_INIT_TABLE(GPIOC, GPIO_PIN_3);

void GT20L16_IO_Init(void){
	BSP_SwSPI_Init(1);
	IO_Init(&GT20L16_CS, IO_Mode_OUT);
	IO_Set(&GT20L16_CS, 1);
}

int GT20L16_IO_Read(uint32_t address, uint8_t buffer[], uint32_t size){
	uint32_t i;
	
	IO_Set(&GT20L16_CS, 0);
	//Instruction: Fast Read
	BSP_SwSPI_TxRx(0x0B);
	//Address
	BSP_SwSPI_TxRx(address >> 16);
	BSP_SwSPI_TxRx(address >> 8);
	BSP_SwSPI_TxRx(address);
	//Dummy
	BSP_SwSPI_TxRx(0);

	for(i = 0; i < size; i++){
		buffer[i] = BSP_SwSPI_TxRx(0x00);
	}	
	
	IO_Set(&GT20L16_CS, 1);
	return 0;
}





